<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header('修改栏目')"></head>
<th:block th:include="include :: oly_tagsinput_css" />
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-column-edit"
			th:object="${cmsColumn}">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">上级栏目：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
						<input class="form-control" type="text"
							onclick="selectColumnTree()" id="treeName" readonly="true"
							th:value="${parentName}"> <span class="input-group-addon"><i
							class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">栏目ID：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="columnId"
						id="columnId" th:field="*{columnId}" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">栏目类型：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dictTag.getType('cms_column_type')}">
						<input type="radio" th:id="${dict.dictCode}" name="parent" th:value="${dict.dictValue}" th:checked="${dict.default}" th:field="*{parent}" required>
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">栏目名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="columnName"
						th:field="*{columnName}" id="columnName" required minlength="2" maxlength="8">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label is-required">链接地点：</label>
				<div class="col-sm-8">
				<div class="radio-box" th:each="dict : ${@dictTag.getType('cms_column_locate')}">
					<input type="radio" th:id="${dict.dictCode}" name="columnLocate" th:value="${dict.dictValue}" th:checked="${dict.default}" th:field="*{columnLocate}" required>
					<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
				</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">打开方式：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dictTag.getType('cms_column_open')}">
						<input type="radio" th:id="${dict.dictCode}" name="openType" th:value="${dict.dictValue}" th:checked="${dict.default}" th:field="*{openType}" required>
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">栏目排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum"
						th:field="*{orderNum}" required >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">栏目状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dictTag.getType('cms_column_visible')}">
						<input type="radio" th:id="${dict.dictCode}" name="visible" th:value="${dict.dictValue}"  th:field="*{visible}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目地址：</label>
				<div class="col-sm-8">
					<input id="url" placeholder="栏目地址" name="columnUrl" th:field="*{columnUrl}"
						class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目图标：</label>
				<div class="col-sm-8">
					<input  name="columnIcon" class="form-control"
						th:field="*{columnIcon}" type="text" placeholder="栏目图标">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">权限标识：</label>
				<div class="col-sm-8">
					<input id="perms" name="perms" th:field="*{perms}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" >[[*{remark}]]</textarea>
                </div>
            </div>
			<div class="form-group">
				<label class="col-sm-3 control-label">关键词：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="keywords" placeholder="关键词" th:field="*{keywords}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">描述：</label>
				<div class="col-sm-8">
					<textarea name="description" class="form-control" >[[*{description}]]</textarea>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<th:block th:include="include :: oly_tagsinput_js" />
	<script>
        var prefix = ctx + "cms/column";
        	  //关键词
		  $("input[name='keywords']").tagsinput({
			maxTags: 4,
			maxChars: 8
		});
        $("#form-column-edit").validate({
        	rules:{
        		openType:{
        			required:true,
        		},
        		parent:{
        			required:true,		
        		},
				parentId:{
				  required:true,
				  digits:true
				},
				visible:{
				  required:true
				},
        		orderNum:{
					required:true,
        			digits:true
        		},
        		columnName:{
        			required:true,
					rangelength:[2,8],
        			remote: {
                        url: prefix + "/checkColumnNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"parentId": function() {
		                		return $("input[name='parentId']").val();
		                    },
                        	"columnName" : function() {
                                return $.common.trim($("#columnName").val());
                            },
                            'columnId':$("#columnId").val()             
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        	},
        	messages: {
                "columnName": {
                    remote: "导航名已存在"
                }
               
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-column-edit').serialize());
	        }
	    }

            /*栏目管理-新增-选择菜单树*/
			function selectColumnTree() {
        	var treeId = $("#treeId").val();
        	var columnId = treeId > 0 ? treeId : 1;
        	var url = prefix + "/selectColumnTree/" + columnId+"?parent=0&visible=1";
			var options = {
				title: '栏目选择',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
	
		function doSubmit(index, layero){
			var body = $.modal.getChildFrame(index),
			treeId=body.find('#treeId').val();
			if( treeId==$("input[name='columnId']").val()){
				$.modal.msgError("不能选择自己为父节点")
			}
			else{
				$("#treeId").val(treeId);
				$("#treeName").val(body.find('#treeName').val());
				$.modal.close(index);
			}

		}
    </script>
</body>
</html>
